package com.geekaca.testthread.work.testreduce;

public class ReduceThread extends Thread {
    private Total total;

    public ReduceThread(Total total) {
        this.total = total;
    }

    public synchronized void run() {
        while (total.getTotal() >= 0) {


            synchronized (this) {
                total.reduceTotal();
                System.out.println(this.getName() + " total: " + total.getTotal());
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
